package com.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.ConfigurableApplicationContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * @author yexi
 */
@Slf4j
@SpringBootApplication
@EnableSwagger2
public class SwaggerApplication {
    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext context = SpringApplication.run(SwaggerApplication.class, args);
        Integer port = context.getBean(ServerProperties.class).getPort();
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        System.out.println("成功注册的docket: " + Arrays.toString(context.getBeanNamesForType(Docket.class)));
        log.info("服务已启动，原生swagger文档访问地址：http://{}:{}/swagger-ui.html", hostAddress, port == null ? 8080 : port);
        log.info("服务已启动，Knife4j增强接口文档访问地址：http://{}:{}/doc.html", hostAddress, port == null ? 8080 : port);
    }
}